package com.xyy.saas.payment.controller;

import com.alibaba.fastjson.JSON;
import com.xyy.saas.payment.cashier.core.vo.ChannelLoginVO;
import com.xyy.saas.payment.channel.login.core.bo.ChannelLoginResultBO;
import com.xyy.saas.payment.channel.login.core.service.ChannelLoginService;
import com.xyy.saas.payment.common.exception.PaymentException;
import com.xyy.saas.payment.cores.vo.ResultVO;
import com.xyy.saas.payment.util.JSONUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wangtianqi
 * @date 2020/7/6 17:28
 */
/** 第三方登录认证接口 */
@RestController
@RequestMapping("/api/channel")
public class ChannelLoginController {

    private static Logger LOGGER = LoggerFactory.getLogger(ChannelLoginController.class);

    @Autowired
    private ChannelLoginService channelLoginService;

    /** 收银台-预支付接口(不必关注) */
    @PostMapping("/login")
    public ResultVO<ChannelLoginResultBO> login(@RequestBody ChannelLoginVO channelLoginVO) {
        try {
            LOGGER.info("ChannelLoginController#login begin channelLoginVO:{}", JSON.toJSONString(channelLoginVO));
            ChannelLoginResultBO bo = channelLoginService.login(channelLoginVO);
            return ResultVO.createSuccess(bo);
        }
        catch(Exception e) {
            LOGGER.error(e.getMessage() + ", channelLoginVO=" + JSONUtils.toJSON(channelLoginVO), e);
            return ResultVO.createError("登录授权失败");
        }
    }

}
